package com.guessdroid.sensing;

import java.util.ArrayList;


public class AS_avgAccChange extends AbstractSensor implements java.io.Serializable
{
	private static final long serialVersionUID = -5771483409695929816L;
	public final String name="avg Acc change";

	public ArrayList<Float> process(RawData rawdata, int interval)
	{
		ArrayList<Float> ret=new ArrayList<Float>();
		int i=2;float accumulator=0;int interval_count=0;
		float old_x=1,old_y=2,old_z=3;
		while (i<rawdata.accStamps.size())
		{
			if ((1+interval_count)*interval<rawdata.accStamps.get(i))
			{
				ret.add(accumulator); // divide by interval if differing intervals
				accumulator=0;
				interval_count++;
			}
			else
			{
				if (i>2) // slight inaccuracy for the first interval?
				{
					float x=old_x-rawdata.accData.get(i-2);
					float y=old_y-rawdata.accData.get(i-1);
					float z=old_z-rawdata.accData.get(i);
					accumulator+=Math.sqrt(x*x+y*y+z*z); // euclidean distance, differences
				}
				old_x=rawdata.accData.get(i-2);
				old_y=rawdata.accData.get(i-1);
				old_z=rawdata.accData.get(i);
				i+=3;
			}
		}
		return ret;
	}

}
